const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    let str=await readline()
    str=str.slice(2)

    let res=0
    let index=str.length-1
    let map=new Map([["0",0],["1",1],["2",2],["3",3],["4",4],["5",5],["6",6],["7",7],["8",8],["9",9],["A",10],["B",11],["C",12],["D",13],["E",14],["F",15]])
    for(let i=0;i<str.length;i++){
        res+=Math.pow(16,index)*map.get(str[i])
    }
    console.log(res);
}()
